<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>透明的单例类的编写</title>
</head>
<body>
<script>
    var CreateDiv = (function () {
        var instance ;
        var CreateDiv = function (html) {
            if(instance){
                return instance
            }
            this.html = html;
            this.init();
            return instance = this;
        };
        CreateDiv.prototype.init = function () {
            // 创建元素
            var div = document.createElement('div');
            div.innerHTML = this.html;
            // 挂在div
            document.body.appendChild(div)
        }
        return CreateDiv;
    })()
    var a = new CreateDiv('sven1');
    var b = new CreateDiv('sven2');
    alert(a===b);


    var CreateDiv = function (html) {
        if(instance){
            return instance;
        }
        this.html = html;
        this.init();
        return instance = this;

    }
</script>
</body>
</html>